package org.example.lotterysystem.dao.mapper;


import org.apache.ibatis.annotations.*;
import org.example.lotterysystem.dao.dataobject.Encrypt;
import org.example.lotterysystem.dao.dataobject.UserDO;

import java.util.List;

@Mapper
public interface UserMapper {


    /**
     *
     * 查询邮箱是否被使用
     * @param email
     * @return
     */
    @Select("select count(*) from user where email=#{email}")
    int countByEmail(@Param("email") String email);

    @Select("select count(*) from user where phone_number=#{phoneNumber}")
    int countByPhoneNumber(@Param("phoneNumber") Encrypt phoneNumber);
    @Insert("insert into user (email,identity,password,phone_number,user_name)" +
            " values (#{email},#{identity},#{password},#{phoneNumber},#{userName})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(UserDO userDO);

    @Select("select * from user where phone_number=#{phoneNumber}")
    UserDO selectPasswordByPhoneNumber(Encrypt phoneNumber);

    @Select("select password from user where email=#{mail}")
    String  selectPasswordByMail(String mail);

    @Select("<script>" +
            " select * from user" +
            "<if test=\"identity!=null\">" +
            "where identity = #{identity}" +
            "</if>" +
            "order by id desc" +
            "</script>")
    List<UserDO> selectUserListByIdentity(@Param("identity") String identity);


    @Select("<script>select id from user where id in " +
            "<foreach item='items' collection='items' open='('separator=',' close=')' #{items} </foreach> </script> ")
    List<Long> selectExistsByIds(@Param("items") List<Long> id);

    @Select("<script>select id from user where id in " +
            "<foreach item='items' collection='items' open='('separator=',' close=')' #{items} </foreach> </script> ")
    List<UserDO> bathSelectByIds(@Param("items") List<Long> userIds);

}
